<?php
namespace app\controllers;
use app\models\AdminModel;
use wlcat\http\controllers\Controller;

class LoginController extends Controller{
    public function index()
    {
        $this->assignFormToken();
        $this->display();
    }
    public function login()
    {
        //检查表单token
        $this->checkFormToken();
        $user       = $this->request->input('post.user');
        $model      = new AdminModel();
        $user       = $model->get('select * from '.$model->getTable()." where user = '{$user}' limit 1");
        $password   = $this->request->input('post.password');
        if (checkPassword($password, $user['password'], $user['rand']))
        {
            $this->request->setInput('session.uid', $user['id']);
            $this->request->setInput('session.user', $user['user']);
            $this->request->setInput('session.loginExpire', time()+60*60*12);
        }
        redirect('index');
    }
    
}